<template>
  <div class="main-sheet">
    <div class="item-list">
    <div class="item" v-for="(sheet,index) in sheetList">
      <span>{{ sheet.aliases }}</span>
      <a @click="del(sheet)">删除</a>
      <a @click="edit(sheet)">编辑</a>
    </div>
    </div>
    <!-- 没有更多数据 -->
    <div class="no-data">亲，没有更多了～</div>
    <div class="foot" @click="add">新增电子面单</div>
    <tanchuan ref="tanchuanDel" :title="title" :content="content" @doCancle="doCancleDel"
              @doConfirm="doConfirmDel"></tanchuan>
    <toast ref="toast"/>

  </div>
</template>

<script>

    import tanchuan from '@/components/tanchuan'
    import toast from '@/components/toast'
    import api from '@/utils/api'

    export default {
        components: {tanchuan, toast},

        data() {
            return {
                title: "确定删除",
                content: '确定删除此面单？',
                toastMsg: "",
                toastVisible: false,
                sheetList: [],
                currentSheet: null
            }
        },

        created() {

        },

        onLoad(options) {
            this.list();
        },

        onShow(){
            this.list();
        },

        methods: {
            //获取列表
            list() {
                var _this = this;
                wx.request({
                    url: wx.getStorageSync("otherPath") + api.queryAllUserWaybillTemplateWithAttr + "?ecstoken=" + wx.getStorageSync('sessionId'),
                    method: "POST",
                    header: {
                        ecstoken : wx.getStorageSync('sessionId'),
                        fslb : wx.getStorageSync('fslb')
                    },
                    data: {},
                    success(res) {
                        _this.sheetList = res.data.data;
                    },
                    fail() {
                        _this.$refs.toast.show('网络异常')
                    }
                })
            },

            del(sheet) {
                this.currentSheet = sheet;
                this.$refs.tanchuanDel.show();
            },
            edit(sheet) {
                var sheetstr = JSON.stringify(sheet)
                var url = "../addelecsheet/main?sheet=" + encodeURIComponent(sheetstr) + "&type=1";
                mpvue.navigateTo({url})
            },
            add() {
                var url = "../addelecsheet/main?type=0";
                mpvue.navigateTo({url})
            },
            doCancleDel() {
                this.$refs.tanchuanDel.hidden();
                this.$refs.toast.show('取消删除')
            },
            doConfirmDel() {
                var _this = this;
                wx.request({
                    url: wx.getStorageSync("otherPath") + api.deleteUserWaybillTemplate + "?ecstoken=" + wx.getStorageSync('sessionId'),
                    method: "POST",
                    header: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        ecstoken : wx.getStorageSync('sessionId'),
                        fslb : wx.getStorageSync('fslb')
                    },
                    data: {
                        id : _this.currentSheet.id,
                        companyType : _this.logisticsCompanyType,
                        templateType : _this.templateType
                    },
                    success(res) {
                        _this.$refs.tanchuanDel.hidden();
                        _this.$refs.toast.show('删除成功');
                        _this.list();
                    },
                    fail() {
                        _this.$refs.toast.show('网络异常')
                    },
                })
            }
        }
    }
</script>

<style lang="wxss">
  page {
    width: 100%;
    height: 100%;
    background-color: #F7FBFF;
  }
</style>

<style scoped>
  .main-sheet {
    width: 100%;
    height: 100%;
  }

  .item-list{
    padding-left: 15px;
    padding-right: 15px;
    background: rgba(255, 255, 255, 1);
  }

  .item {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(55, 62, 79, 1);
    line-height: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 1);
    border-bottom: 1px solid #e8eaf0;
  }

  .item a {
    width: 14%;
    height: 40px;
    line-height: 40px;
    float: right;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(0, 119, 255, 1);
  }

  .no-data {
    color: #a3aab7;
    width: 2rem;
    height: 0.3rem;
    margin: 0 auto;
    margin-top: 0.3rem;
    text-align: center;
    font-size: 0.24rem;
    line-height: 0.26rem;
  }

  .foot {
    text-align: center;
    vertical-align: middle;
    width: 100%;
    height: 40px;
    position: fixed;
    bottom: 0;
    background-color: #0077FF;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
    line-height: 40px;
  }
</style>
